home *** CD-ROM | disk | FTP | other *** search
/ Enter 2010 January / ENTER_2010_01.iso / Programy / Gry / Base_Invaders_ / BaseInvadersSetup1.3.exe / {app} / Scripts / Intro.lua < prev    next >
Encoding:
Text File  |  2007-01-25  |  8.1 KB  |  339 lines

  1. -----------------------------------------
  2. --            INTRO IMAGE BOX
  3. -----------------------------------------
  4.  
  5. dofile( "Scripts/IntroImagePopup.lua" )
  6. dofile( "Scripts/CinemaSystem.lua" )
  7.  
  8. -----------------------------------------
  9. --            GAME INTRO
  10. -----------------------------------------
  11.  
  12. -- Create all the data used by the intro:
  13. function IntroStartup()
  14.     G.SetLoopingMusic(  "Music/moxie_socks.mp3");
  15.     
  16.     -- Recreate the camera:
  17.     local cam = G.GetCogName( "Camera" )
  18.     if( cam ~= nil and cam.IsValid() ) then
  19.         cam.Destroy()
  20.     end
  21.  
  22.     IntroZoomSize = false
  23.     SetImagePopupTiming( 0, 1, 1.5 );
  24.     IntroImageSize = Vector3(2, 2, 0 )
  25.     IntroImagePopup( "Textures/Black.bmp" )
  26.  
  27.     IntroCam = G.Create( "Data/GameCamera.xml" );
  28.     IntroCam.EnableCamera( true, true, true )
  29.  
  30.     IntroCam.SetPosition( Vector3( 220, 5, 330 ) )
  31.     IntroCam.SetDirection( Vector3( 0.1,0.25,-1) )
  32.  
  33.     -- Create the level to place the camera on:
  34.     IntroLevel = G.Create( "Data/Levels/Campaign1.xml" )--IntroLevel.xml") 
  35.  
  36.  
  37.     --local towerPos = Tower.GetPosition();
  38.     --IntroCam.CinemaLookAt( Tower );
  39.     
  40.     -- Create the starting Invaders, and hand:
  41.     G.SetLightTime( 6 );
  42.     
  43.     
  44.     -- PRELOAD ALL OTHER GAME ASSETS!
  45.     
  46.     StartCinematic()
  47. end
  48.  
  49. function IntroShutdown()
  50.  
  51.     EndCinematic()
  52.  
  53.     local lvl = G.GetCogName( "IntroLevel" )
  54.     
  55.     if( lvl ~= nil and lvl.IsValid() ) then
  56.         lvl.Destroy()
  57.     end
  58.     
  59.     GMain["IntroUpdate"] = nil
  60.     KillImagePopup()
  61.     
  62.     G.SimpleStopSound( "IntroMusic" );
  63.     
  64.     G.DestroyGroup("invaders");
  65.     G.DestroyGroup("spawners");
  66.     G.DestroyGroup("tower");
  67.     G.DestroyGroup("traps");
  68.     G.DestroyGroup("walls");
  69.     G.DestroyGroup("effects");
  70.     G.DestroyGroup("cursor");
  71.     G.DestroyGroup("level");
  72.     G.DestroyGroup("doodads");
  73.  
  74.     G.SunMoveRate( 0 )
  75.     G.SetTimeOfDay( 0 )
  76.     G.SetLightTime( 0 );
  77.     
  78.     KillCinemaBars();
  79.     
  80.     G.ActivateBackground( 0 );
  81.  
  82.     G.DestroyGroup("camera");
  83.     CreateBasicCamera()            -- ALWAYS have an active camera
  84. end
  85.  
  86.  
  87. -- 255, (20), 190
  88. function IntroSequence()
  89.  
  90.     -- Random weather
  91.     G.DestroyGroup( "effects" );
  92.     
  93.     if( math.random(3) == 1 ) then
  94.         G.Create( "Data/RainCell.xml" )
  95.     elseif( math.random(5) == 1 ) then
  96.         G.Create( "Data/SnowCell.xml" )
  97.     end
  98.  
  99.     -- Fade in
  100.     G.SunMoveRate( -0.05 )
  101.     G.SetTimeOfDay( 0.35 * math.pi )    
  102.     
  103.     FadeIn( 1.5 );
  104.     GameWait( 1.5 )
  105.  
  106.     -- Show DP logo
  107. --    SetImagePopupTiming( 0.5, 1, 0.5 );
  108. --    IntroImageSize = Vector3(1.00, 0.75, 0 )
  109. --    IntroImagePopup( "Textures/DP512.png" )
  110. --    GameWait( 2 )    
  111.     
  112.     -- Show 7E logo
  113.     SetImagePopupTiming( 1, 2, 1 );
  114.     IntroImageSize = Vector3(0.75, 0.75, 0 )
  115.     IntroImagePopup( "Textures/GearLogo.png" )
  116.     GameWait( 4 )    -- xchanged
  117.     
  118.     SetImagePopupTiming( 1, 79, 5 )
  119.     IntroImageSize = Vector3(2.0, 1.0, 0 )
  120.     IntroImagePopup( "Textures/Logo_2.png" )
  121.     GameWait( 1 )
  122.  
  123.     -- Plot intro:
  124.     -- "One day..."
  125.     -- "I'm traitor!"
  126.     -- "Sanctuary!"
  127.     -- Spawns invaders
  128.     -- "We'll get you!"
  129.     -- Hammers, splat
  130.     -- they attack and the Plot intro fades to the pretty intro
  131.  
  132.     -- Loop forever:
  133.     GameWait( 75 )
  134.     FadeOut( 1.5 );
  135.     GameWait( 1.5 )
  136. --[[
  137.     for loopnum = 0, 10 do 
  138.         -- Create an invader, kill the previous one
  139.         local invName;
  140.         local tempNum = math.random(0,5);
  141.         
  142.         if( tempNum == 0 ) then
  143.             invName = "Basic"
  144.         elseif( tempNum == 1 ) then
  145.             invName = "Miner"
  146.         elseif( tempNum == 2 ) then
  147.             invName = "Spiker"
  148.         elseif( tempNum == 3 ) then
  149.             invName = "Squad"
  150.         elseif( tempNum == 4 ) then
  151.             invName = "Bomber"            
  152.         elseif( tempNum == 5 ) then
  153.             invName = "Stacker"
  154.         end
  155.         
  156.         local invToKill = G.CreateAt( invName,  Vector3( 200, 0, 100) ) 
  157.                                                 -- Vector3( math.random(-5,5), 0, math.random(-5,5) ) )
  158.         GameWait( 5 )
  159.         
  160.         invToKill.Destroy()
  161.     end
  162.     FadeOut( 1.5 );
  163.     GameWait( 1.5 )
  164.  
  165.     IntroZoomSize = false
  166.     SetImagePopupTiming( 0, 0.05, 1.5 );
  167.     IntroImageSize = Vector3(2, 2, 0 )
  168.     IntroImagePopup( "Textures/Black.bmp" )
  169.  
  170.     G.SunMoveRate( -0.05 )
  171.     G.SetTimeOfDay( 0.35 * math.pi )
  172.  
  173.     local lookAtPoint = Vector3( 255, 20, 190 )
  174.     local camPos = Vector3( 300, 6.5, 150 )
  175.     -- local camDir = lookAtPoint - camPos                    -- Vector3( -0.725, 0.22, 0.65 )
  176.     
  177.     IntroCam.SetPosition( camPos );
  178.     IntroCam.SetDirection( lookAtPoint - camPos );
  179.  
  180.     GameWait( 1.5 );
  181.     
  182.     -- Play Intro Music
  183.     G.SimpleLoadSoundVar( "IntroMusic", "SFX/9th.ogg", 0 );        
  184.     G.SimplePlaySound( "IntroMusic" );
  185.     
  186.     -- Fade in the Digipen logo
  187.     IntroZoomSize = true
  188.     SetImagePopupTiming( 0.05, 1.2, 0.05 );
  189.     IntroImageSize = Vector3(1.00, 0.75, 0 )
  190.     IntroImagePopup( "Textures/DP512.png" )
  191.     GameWait( 1.5 )
  192.  
  193.     -- Fade in the Seventh Sigma logo
  194.     SetImagePopupTiming( 0.05, 1.2, 0.05 );
  195.     IntroImageSize = Vector3(0.75, 0.75, 0 )
  196.     IntroImagePopup( "Textures/GearLogo.png" )
  197.     GameWait( 1.75 )    
  198.     
  199.     -- The logo fades in and a "Click Enter Menu" button appears 
  200.     SetImagePopupTiming( 0.1, 58, 5 )
  201.     IntroImageSize = Vector3(2.0, 1.0, 0 )
  202.     IntroImagePopup( "Textures/Logo_2.png" )
  203.     GameWait( 1 )    
  204.     
  205.     -- Zoom in on 3 invader and some flowers
  206.     G.CreateAt( "Basic", Vector3( 250, 50, 210 ) )
  207.     G.CreateAt( "Spiker", Vector3( 240, 50, 170 ) )
  208.     G.CreateAt( "Stacker", Vector3( 270, 50, 185 ) )
  209.     G.CreateAt( "Basic", Vector3( 260, 50, 170 ) )
  210.     G.CreateAt( "Spiker", Vector3( 275, 50, 200 ) )
  211.     G.CreateAt( "Stacker", Vector3( 240, 50, 170 ) )
  212.     
  213.     -- Raise up and circle around the tower:
  214.     
  215.     local starttime = GameTime;    
  216.     while( GameTime - starttime < 10 ) do    
  217.         camPos[1] = camPos[1] + GameTimeDiff * 5;
  218.         IntroCam.SetDirection( lookAtPoint - camPos );
  219.         IntroCam.SetPosition( camPos );
  220.         coroutine.yield();    
  221.     end
  222.     
  223.     starttime = GameTime;
  224.     startSpinVal = math.pi * 1.75 * 4.0
  225.     
  226.     G.SunMoveRate( -0.03 )
  227.     while( GameTime - starttime < 35 ) do    
  228.         startSpinVal = startSpinVal + GameTimeDiff
  229.         camPos[0] = 255 + math.cos( startSpinVal / 4.0 ) * 60
  230.         camPos[2] = 190 + math.sin( startSpinVal / 4.0 ) * 50
  231.         IntroCam.SetDirection( lookAtPoint - camPos );
  232.         IntroCam.SetPosition( camPos );
  233.         coroutine.yield();    
  234.     end
  235.     
  236.     G.SunMoveRate( -0.05 )
  237.     starttime = GameTime;
  238.     while( GameTime - starttime < 11 ) do    
  239.         camPos[1] = camPos[1] - GameTimeDiff * 5;
  240.         IntroCam.SetDirection( lookAtPoint - camPos );
  241.         IntroCam.SetPosition( camPos );
  242.         coroutine.yield();    
  243.     end
  244.  
  245.     GameWait( 8 )
  246.  
  247.     IntroZoomSize = false
  248.     SetImagePopupTiming( 2, 10, 0 );
  249.     IntroImageSize = Vector3(2, 2, 0 )
  250.     IntroImagePopup( "Textures/Black.bmp" )
  251.     
  252.     GameWait( 2 )
  253.     
  254.     -- Invader happy sounds
  255.     -- Invaders are smiling and walking back and forth when ...
  256.     
  257.     -- Dramatic Swoosh sound
  258.     -- The shadow of the hand moves over them ...
  259.     
  260.     -- Invaders stop, have Confusion effect ...
  261.     
  262.     -- Walls drop on flowers
  263.     
  264.     -- Invaders switch to MAD version
  265.     
  266.     -- New invaders come in from the background
  267.     
  268.     -- Zoom back and watch as invaders attack a newly built tower
  269.     
  270.     -- After 1-2 minutes, restart the intro:
  271.     -- GameWait( 60 )    
  272.     
  273.  
  274.     G.DestroyGroup("invaders");
  275.     G.DestroyGroup("tower");
  276.     G.DestroyGroup("walls");
  277.     
  278.     GameWait( 1 )    -- Wait atleast 1 section for the objects to be deleted!
  279.     
  280.     IntroLevel.LoadLevelData()    
  281.     
  282.     ]]--
  283. end
  284.  
  285. function CheckIntroCompletion()
  286.     -- Keep updating as long as the user doesn't click/
  287.     if( --false and ( 
  288.         G.KeyTriggered( "Space" ) or 
  289.         G.KeyTriggered( "Enter" ) or 
  290.         G.KeyTriggered( "Escape" ) or 
  291.         G.MouseTriggered( 0 ) or 
  292.         G.MouseTriggered( 1 ) ) then
  293.     
  294.         -- If not done with the intro, 
  295.         -- Skip to the end of the intro:
  296.         
  297.         -- Else, open the Main Menu:
  298.         IntroShutdown()
  299.         MainMenu.OpenWindow( "StartWindow", false );
  300.         --invaderpeida crash
  301.         G.File( "Data/BasicCamera.xml" );
  302.             
  303. --        dofile( "Scripts/Startup.lua" )
  304.     end
  305.  
  306. end
  307.  
  308. -- Update Function:
  309. function IntroUpdate()
  310.     
  311.     CheckIntroCompletion()
  312.     
  313.     -- Update the Intro Sequence
  314.     if( introRoutine ) then    
  315.         local con, error = coroutine.resume( introRoutine )
  316.  
  317.         -- Restart the Intro Sequence:
  318.         if( con == false ) then    
  319.             G.Mes( error )
  320.             introRoutine = coroutine.create( IntroSequence )
  321.         end    
  322.     end    
  323.  
  324. end
  325.  
  326.  
  327. function PlayIntro()
  328.     MainMenu.CloseWindow( "StartWindow" )
  329.     MainMenu.CloseWindow( "BonusWindow" )
  330.     G.ActivateBackground( -1 );    
  331.     IntroStartup()
  332.     introRoutine = coroutine.create(IntroSequence);
  333.     GMain["IntroUpdate"] = IntroUpdate;
  334. end
  335.  
  336.  
  337.  
  338.  
  339.